// pages/account/account.js
//获取应用实例
var app = getApp();
var util = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabnav: {
            tabnum: 5,
            tabitem: []
        },
        columnId: '',
        addtellToo: {
            addtellHidden: false, //弹出框显示/隐藏
        },
    },
    modalConfirm: function () {
        //弹出框确认操作
        this.setData({
            addtellToo: {
                addtellHidden: true,
            }
        })
    },
    modalCancel: function () {
        //弹出框取消操作
        this.setData({
            addtellToo: {
                addtellHidden: false,
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.emit('acceptDataFromOpenedPage', { data: "id" });
        eventChannel.emit('someEvent', { data: "id" });
        // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
        eventChannel.on('acceptDataFromOpenerPage', function (data) {
            that.setData({
                columnId: data
            })
            that.getList()
        })

    },
    setTab: function (e) {
        console.log(e)
        const id = e.currentTarget.dataset.id;
        this.setData({
            showtab: id,
        })
        this.findList(id)
    },
    // 分享
    onShareAppMessage: function (res) {
        var that = this;
        return {
            title: '贷投狗小程序',
            path: 'pages/account/account',
            success: function (res) {
                that.shareClick();
            },
            fail: function (res) {
            }
        }
    },
    getList: function () {
        let that = this
        let columnId = that.data.columnId
        util.https(app.globalData.api + "/applet/column/tree/" + columnId, "GET", {},
            function (data) {
                if (data.code == 200) {
                    that.setData({
                        'tabnav.tabitem': data.data,
                        showtab: data.data[0].id
                    })
                    let id = data.data[0].id
                    that.findList(id)
                } else {
                    util.toolTip(that, data.message)
                }
            }
        )

    },
    findList: function (id) {
        let that = this
        util.https(app.globalData.api + "/applet/column/content/" + id, "GET", {},
            function (data) {
                if (data.code == 200) {
                    that.setData({
                        columnData: data.data
                    })
                } else {
                    util.toolTip(that, data.message)
                }
            }
        )
    },
    jinjian: function () {
        wx.redirectTo({
            url: '/pages/order/order',
        })
    },
    fuwenben: function (e) {
        console.log(e)
        let classify = wx.getStorageSync('classify')
        let fwbClassify = e.currentTarget.dataset.item.classify
        this.setData({
            itemClassify: fwbClassify
        })
        if (fwbClassify != 0) {
            if (fwbClassify >= classify || fwbClassify == null) {
                wx.navigateTo({
                    url: '/pages/imge/imge',
                    success: function (res) {
                        let data = e.currentTarget.dataset.item
                        data.load = false
                        res.eventChannel.emit('acceptDataFromOpenerPage', data)
                    }
                })
            } else {
                this.setData({
                    addtellToo: {
                        addtellHidden: true
                    }
                })
            }
        }
    }
})